/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Animation.Animations;

import Scenery.BaseSprite;
import main.DumbMath;
import com.jme3.math.Matrix3f;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import Animation.Animation;
import Animation.Animation;
import Scenery.BaseCharacter;
import Scenery.BaseSprite;
import main.DumbMath;


/*
 * 
 * @author: Ziden
 * 
 */

public class HandBangle extends Animation {

    public HandBangle(BaseCharacter dude, int frame) {
        super(dude, 40);
        storedValues = 2; // each hand
        buildAnimation();
    }
  
    // HANDS
    private float handAngle = 0f;
    private float inverseHandAngle = 0f;
    private float handSpeed = 0.25f;

    //initial states
    private Vector3f rhand;
    private Vector3f lhand;


    @Override
    public void gotoInitialState() {
        animationBody.getrHandNode().setLocalTranslation(rhand);
        animationBody.getrHandNode().setLocalTranslation(lhand);
        handAngle =0f;
        frame = 0;
        inverseHandAngle = 0f;
        

    }

    @Override
    public String getName() {
        return "HandBangle";
    }

    @Override
    public void saveInitialState() {
        rhand = animationBody.getrHandNode().getLocalTranslation().clone();
        lhand = animationBody.getrHandNode().getLocalTranslation().clone();
    }

    @Override
    protected void buildFrame() {
         if(frame < maxFrame/4) { 
             
           handAngle += handSpeed;
           inverseHandAngle -= handSpeed;
       } 
       else if(frame >= maxFrame/4 && frame < (maxFrame*3)/4) {
           
           handAngle -= handSpeed;
           inverseHandAngle += handSpeed;
       }
       else if(frame >= (maxFrame*3)/4) {
          handAngle += handSpeed;
          inverseHandAngle -= handSpeed;
       } else {
            handAngle -= handSpeed;
           inverseHandAngle += handSpeed;
       }     
         
       animationFrames[frame][0] = handAngle-0.1f;
       animationFrames[frame][1] = inverseHandAngle-0.1f;
         
    }

    @Override
    public void performFrame() {
        DumbMath.rotate("Z", animationFrames[frame][1],  0.2f, animationBody.getrHandNode(),0.2f,0.5f, 0.7f);
        DumbMath.rotate("Z", animationFrames[frame][0],  0.2f, animationBody.getlHandNode(),0.2f,0.5f, -0.7f); 
    }

    @Override
    protected float getCicleRunTime() {
        return 20;
    }

}
